﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

using ZFB.Common;
using ZFB.DTO;
using ZFB.IServices;

namespace ZFB.WebAPI.Controllers
{
    /// <summary>
    /// 字典
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class IdNameController : ControllerBase
    {
        private readonly IIdNameServices _idNameServices;

        public IdNameController(IIdNameServices idNameServices)
        {
            _idNameServices = idNameServices;
        }
        /// <summary>
        /// 添加字典项
        /// </summary>
        /// <param name="typeName"> 户型0,房屋状态1,房屋类型2,装修状态3</param>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult> AddNew(IdNameEnum typeName,string name) 
        {
           return _idNameServices.AddNewAsync(typeName, name);
        }
        /// <summary>
        /// 查询字典项
        /// </summary>
        /// <param name="typeName"> 户型0,房屋状态1,房屋类型2,装修状态3</param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult> GetByType(IdNameEnum typeName)
        {
            return _idNameServices.GetAllAsync(typeName);
        }
        /// <summary>
        /// 通过id查询字典项
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult> GetById(long id)
        {
            return _idNameServices.GetByIdAsync(id);
        }
    }
}
